package ru.spies.entities;

import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.REFRESH;
import static javax.persistence.FetchType.EAGER;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


/**
 * The persistent class for the document database table.
 * 
 */
@Entity
@Table(name="document")
@NamedQuery(name="Document.findAll", query="SELECT d FROM Document d")
public class Document implements Serializable, ITableClass {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(unique=true, nullable=false)
	private Integer id;

	@Column(name="text_link", nullable=false, length=2147483647)
	private String textLink;

	//bi-directional many-to-one association to Importance
	@ManyToOne(fetch=EAGER, cascade = { REFRESH, MERGE})
	@JoinColumn(name="id_importance", nullable=false)
	private Importance importance;

	//bi-directional many-to-one association to Task
	@ManyToOne(fetch=EAGER, cascade = { REFRESH, MERGE})
	@JoinColumn(name="id_task")
	private Task task;
	
	//bi-directional many-to-one association to Agent
	@ManyToOne(fetch=EAGER, cascade = { MERGE, REFRESH })
	@JoinColumn(name="id_agent")
	private Agent agent;

	private Object paramForFindQuery=null;
	
	public Document() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTextLink() {
		return this.textLink;
	}

	public void setTextLink(String textLink) {
		this.textLink = textLink;
	}

	public Importance getImportance() {
		return this.importance;
	}

	public void setImportance(Importance importance) {
		this.importance = importance;
	}

	public Task getTask() {
		return this.task;
	}

	public void setTask(Task task) {
		this.task = task;
	}
	
	public Agent getAgent() {
		return this.agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	@Override
	public void setParamForFindQuery(Object param) {
		paramForFindQuery=param;		
	}

	@Override
	public Object getParamForFindQuery() {
		return paramForFindQuery;
	}

	@Override
	public ITableClass createThisObject() {
		return new Document();
	}

	@Override
	public String getQueryForFind() {
		return "SELECT x FROM Document x WHERE x.id = :param";
	}

}